package com.finance.system.support.utils;

//
//import com.finance.system.domain.entity.SystemConfigEntity;
//import com.finance.system.service.systemconfig.ISystemConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
//import java.io.IOException;
//import java.util.List;
import java.util.Properties;

@Component
public class ConfigUtils {

    private static Properties properties;

    private static Properties dbProperties;

    private static String APP_PROPERTIES_PATH = "/application.yaml";

    @Autowired
//    private ISystemConfigService systemConfigService;



    @PostConstruct
    public void init(){
//        Properties properties = new Properties();
//        try {
//            properties.load(getClass().getResourceAsStream(APP_PROPERTIES_PATH));
//            this.properties = properties;
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        List<SystemConfigEntity> list = systemConfigService.list();
//        Properties dbProperties = new Properties();
//        for (SystemConfigEntity configEntity : list) {
//            dbProperties.setProperty(configEntity.getName(),configEntity.getValue());
//        }
//        this.dbProperties = dbProperties;
    }

    public static  String getConfig(String key){
        if(properties.getProperty(key) != null) return properties.getProperty(key);

        return dbProperties.getProperty(key);
    }


}
